<?php
class JPushService
{
    	function postUrl($url,$params = array(),$post = true)
	{
		if(!is_array($params)){
			return false;
		}
		$r = new HttpRequest($url, $post?HttpRequest::METH_POST:HttpRequest::METH_GET);
		$r->addHeaders(array('Content-type' => 'application/x-www-form-urlencoded'));
//		if(count($params)){
//			$r->setQueryData($params);
//		}
		if($post){
                    $r->setPostFields($params);
                }else{
                    $r->setQueryData($params);
                }
		
		try {
		    $r->send();
		    if ($r->getResponseCode() == 200) {
		        return $r->getResponseBody();
		    }
		} catch (HttpException $ex) {
		    return false;
		}
	}

    public function send($alias,$msg,$no)
    {
        $params["app_key"] = "3672d1aaf37cb1993d9977b5";
	$params["sendno"] = $no;
	$params["receiver_type"] = 3;
	$params["receiver_value"] = $alias;
	$params["verification_code"] = md5($params["sendno"].$params["receiver_type"].$params["receiver_value"]."77f03862c579a810e1b502dd");
	$params["msg_content"] = json_encode(array("n_content"=>$msg));
	$params["msg_type"] = 1;
//	$params["apns_production"] = 1;
	$params["platform"] = "android,ios";

	$ret = $this->postUrl("http://api.jpush.cn:8800/v2/push",$params);
        return json_decode($ret);
    }
}


